<?php #$this->headScript()->appendFile($this->JS_PATH . 'calculator.js'); ?>
<div id="MainContent">
    <div class="pageerrorcontainer-validator jscript-error-container">
        <div class="error-iterator"></div>
    </div>


    <?php if ($this->succesMessage != ""): ?>
    <div class='pagemcontainer'>
        <p class='pagemessage'>
            <img src="<?php echo $this->IMAGE_PATH;?>icons/system/accept.gif" class="systemicon" alt="Success" title="Success" />
            <label class='errorlabel'><?php echo $this->succesMessage; ?></label>
        </p>
    </div>
    <?php endif; ?>

    <?php if (count($this->errorMessageArray) > 0): ?>
        <div class="pageerrorcontainer">
            <?php foreach ($this->errorMessageArray as $erroValue): ?>
                <div class="pageoverflow">
                    <img src="<?php echo $this->IMAGE_PATH;?>icons/system/stop.gif" class="systemicon" alt="Error" title="Error" />
                    <label class="errorlabel"><?php echo $erroValue; ?></label>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>			


    <div class="clearb">&nbsp;</div>
    <div id="calculator1"></div>
    <div class="pagecontainer pageoverflow">
        <div class="pageheader">
            Role management
        </div>
        <div style="clear: both;"></div>
        
        <form method="post" action="" id="rolefrm">
            <div id="page_content">
                
                <div class="pageoverflow">
                    <div class="pagetext">Role:</div>
                    <div class="pageinput">
                        <select id="roles" name="roles">
                            <option selected="selected" value="">-- Select Role --</option>
                            <?php foreach ($this->roles as $role_id => $_roles): ?>
                                <?php if ($role_id != '1'):?>
                                <option <?php echo ($this->roleType == $role_id)?"selected":""; ?> value="<?php echo $role_id; ?>"><?php echo $_roles; ?></option>
                                <?php endif;?>
                            <?php endforeach;?>
                        </select>                    
                    </div>
                </div>
                
                <?php foreach($this->resources as $_controller => $_actionData):  ?>
                <div class="pageoverflow">
                    <div class="pagetext"><?php echo ucfirst($_controller); ?></div>
                    <?php if ( count($_actionData) > 0 ):?>
                    <div class="pageinput">
						<ul class="ul-list">
						
                        <?php foreach($_actionData as $_action):  ?>
                            
                        <?php 
                        $checked = '';
                        if (array_key_exists($_controller, $this->roleArray)) {
                            if (array_key_exists($_action['action'], $this->roleArray[$_controller])) {
                                $checked = "checked";
                            }
                        }
                        ?>
                        
                        <?php 
                            $dispalyName = $_action['displayname'];
                            $name = $_controller."_".$_action['action'];
                        ?>
                        
							<li>
							<input type="checkbox" <?php echo $checked; ?>   value="1" name="chk_<?php echo $name;?>" id="role_<?php echo $name;?>">
							<label for="role_<?php echo $name;?>"><?php echo $dispalyName; ?></label>
							</li>
						
                        &nbsp;&nbsp;
                        <?php endforeach; ?>
						</ul>
                    </div>
                    <?php endif; ?>
                    
                </div>
                <?php endforeach; ?>
                
                <div class="pageoverflow">
                    <p class="pagetext">&nbsp;</p>
                    <p class="pageinput">
                        <input type="submit" title="Save changes" value="Save" id="Save" name="save">                        
                    </p>
                </div>
                
                <div style="clear: both;"></div>
            </div>
        </form>  
    </div>
    
    <p class="pageback">
        <a class="pageback" href="<?php echo $this->url(array('controller' => 'index', 'action' => 'index'), null, TRUE) ?>">&#171; Back to Home</a>
    </p>
    <div class="clearb"></div>
</div>
<script>

$(function() {
    $('#roles').change( function(){
        $('#rolefrm').submit();
    });
    
});
</script>